#include "mouse.h"
#include "GQueue.h"

void parse_mouse_event()
{
	MouseData* data = (MouseData*)getGQueue(mouse_queue);
	byte1 = data->b1;
	byte2 = data->b2;
	byte3 = data->b3;
	
	y_over = Y_OVERFLOW(byte1);
	x_over = X_OVERFLOW(byte1);
	
	left_b = LEFT_BUTTON(byte1);
	mid_b = MIDDLE_BUTTON(byte1);
	right_b = RIGHT_BUTTON(byte1);
	
	dx = byte1 & XSGN ? (byte2 - 255) : byte2;
	dy = byte1 & YSGN ? (byte3 - 255) : byte3;
	
	//setting the old color of the pixel where the mouse was before
	set_pixel(x, y, oldColor[0], base);
	set_pixel(x-1, y+1, oldColor[1], base);
	set_pixel(x, y+1, oldColor[0], base);
	
	//increment to the coordinates of the mouse
	x += dx;
	y -= dy;
}

void process_mouse_event()
{

	//testinf if the position of the mouse isn't out of bounds
	if (x >= HRES)
		x = HRES - 1;
	if (y >= VRES)
		y = VRES - 1;
	if (x <= 0)
		x = 1;
	if (y <= 0)
		y = 1;
	
	//stores the color of the pixels where the mouse will be draw, and then draw the mouse
	oldColor[0] = get_pixel(x,y,base);
	oldColor[1] = get_pixel(x+1,y+1,base);
	oldColor[2] = get_pixel(x,y+1,base);
	set_pixel(x, y, 0, base);
	set_pixel(x-1, y+1, 0, base);
	set_pixel(x, y+1, 0, base);
		
}

